<?php
//load header
include "header.php";
$P = new cMyPage();
$locList = array();
$loc['url'] = '/index.php';
$loc['name'] = 'Home';
array_push($locList, $loc);
$loc['url'] = '/friends.php';
$loc['name'] = 'Friends List';
array_push($locList, $loc);
$P->loadLocation($locList);
$P->loadLinks();
$P->loadTitle('Friends List');
$P->loadPreContent('My Profile');
if($P->isLoggedIn()) {
	$fri_array=array();
	?>
  <tr>
    <td>Name</td>
    <td> <?php echo $user->data['username'] . "\n"; ?> </td>
  </tr>
  <?php 
   global $db;
   global $user;
//   select friends. Relation in friends database is not transitive.
  $fri_array=$db->sql_query("SELECT pbu.name, pbu.user_id, f.status 
FROM friends f, phpbb_users pbu
WHERE ((f.user1_id='" . $user->data['user_id'] . "' AND f.user1_id=pbu.user_id) OR (f.user2_id='" . $user->data['user_id']."' AND f.user2_id=pbu.user_id))
ORDER BY f.status, u.name
"); ?>
  <tr>
    <td>Name</td>
    <td>ID</td>
    <td>Status</td>
   </tr> 
<?php 
//include links to userinfo.php page - to display info on each friend
while ($row_fri=$db->sql_fetchrow($fri_array))
  {
	  ?>
  <tr>
    <td><a href="userinfo.php?uid=<?php echo $row_fri['user_id'] ?>"><?php echo $row_fri['name'] ?></a></td>
	<td><?php echo $row_fri['status'] ?></td>  
  </tr>
   
  <?php } 
  
} 
else {
	echo 'Please Log In';
	$P->displayLogin();
}

$P->loadFooter();
?>
